{% extends 'admin_base.html' %}
{% load i18n %}
{% load crispy_forms_tags %}

{% block actions %}
  {% if object %}
    <form method="POST" action="{% url 'templates:duplicate' object.class_name object.id %}">
      {% csrf_token %}
      <button type="submit" class="btn btn-primary">
        {% translate "Duplicate" %}
      </button>
    </form>
    <form method="POST" action="{{ object.delete_url }}">
      {% csrf_token %}
      <button type="submit" class="btn btn-danger">
        {% translate "Delete" %}
      </button>
    </form>
  {% endif %}
{% endblock %}
{% block content %}
<div class="row">
  <div class="col-12">
    <div class="card">
      <form method="POST">
        <div class="card-body">
          {% crispy form %}
          <div class="form-footer">
            <button type="submit" class="btn btn-primary">{% if object %}{% translate "Update" %}{% else %}{% translate "Create" %}{% endif %}</button>
          </div>
        </div>
      </form>
    </div>
  </div>
</div>
{% endblock %}
{% block extra_js %}
<script>
// FOR APPOINTMENTS
// Change when appointment date/time changes
$("#id_fixed_date").on('change', function() {
  if (this.checked == true){
    $("#div_id_date").parent().removeClass("d-none")
    $("#div_id_on_day").parent().addClass("d-none")
  } else {
    $("#div_id_date").parent().addClass("d-none")
    $("#div_id_on_day").parent().removeClass("d-none")
  }
})
// FOR TODOS
$("#id_send_back").on('change', function() {
  if (this.checked == true){
    $(".slack_channel_dissapear").removeClass("d-none")
  } else {
    $(".slack_channel_dissapear").addClass("d-none")
  }
})
// FOR HARDWARE
$("#id_person_type").on('change', function() {
  let selectedItem = $(this).val()
  if (selectedItem == 3){
    $("#div_id_assigned_to").parent().removeClass("d-none")
  } else {
    $("#div_id_assigned_to").parent().addClass("d-none")
  }
})
</script>
{% endblock %}
